import { defHttp } from '@/utils/http/axios'
import { IAddStoreData, IStoreListItem } from './model'
import { DEFAULT_OPTS } from '@/settings'


export enum API {
  STORE = "/storeManage",
  STORE_LIST = "/storeManage/list"
} 

/** 获取门店列表 */
export function getStoreList(name: string = '') {
  return defHttp.get({
    url: API.STORE_LIST + `?name=${name}`
  }, DEFAULT_OPTS)
}

/** 新增店铺 */
export function addStore(data: IAddStoreData) {
  return defHttp.post<IStoreListItem>({
    url: API.STORE,
    data
  }, DEFAULT_OPTS)
}

/** 删除店铺 */
export function deleteStoreById(id: string) {
  return defHttp.delete({
    url: `${API.STORE}/${id}`
  }, DEFAULT_OPTS)
}

/** 编辑店铺信息 */
export function editStoreInfo(data: IStoreListItem) {
  return defHttp.put({
    url: API.STORE,
    data
  }, DEFAULT_OPTS)
}

/** 获取门店下拉选项 */
export async function getStoreOpts(name: string = '') {
  const data = await defHttp.get({
    url: API.STORE_LIST + `?name=${name}`
  }, DEFAULT_OPTS)

  return (data || []).map(item => ({
    label: item.name,
    value: item.id
  }))
}
